package com.yucc.girlimages.ad;

import android.content.Context;
import android.util.Log;

import com.datouniao.AdPublisher.AppConnect;
import com.datouniao.AdPublisher.GetAmountNotifier;
import com.datouniao.AdPublisher.ReceiveNotifier;

public class DatouniaoAd extends AdPlatformAdapter<AppConnect> implements ReceiveNotifier,GetAmountNotifier {
	private static DatouniaoAd sInstance ;
	private static Object sLock = new Object() ;
	
	private DatouniaoAd(Context context) {
		super();
		AppConnect.getInstance(context,this) ;
	}
	
	public static final DatouniaoAd getInstance(Context context) {
		synchronized (sLock) {
			if(sInstance == null) {
				sInstance = new DatouniaoAd(context) ;
			}
		}
		return sInstance ;
	}

	@Override
	public void GetAmountResponse(String currenyName, float amount) {
		Log.d("DatouniaoAd", "----GetAmountResponse amount="+amount) ;
		if(successCallBack != null) successCallBack.getPointSuccess(currenyName, amount) ;
	}

	@Override
	public void GetAmountResponseFailed(String error) {
		Log.d("DatouniaoAd", "----GetAmountResponseFailed error=" + error) ;
		if(failureCallBack != null) failureCallBack.getPointFailure(error) ;
	}

	@Override
	public void GetReceiveResponse(String _currenyName, float receiveAmount, float totalAmount,
			String serverOrderID) {
		GetAmountResponse(_currenyName, totalAmount) ;
	}

	@Override
	public AppConnect getAdInstance(Context context) {
		return AppConnect.getInstance(context);
	}

	@Override
	public void showOffers(Context context) {
		getAdInstance(context).ShowAdsOffers() ;
	}

	@Override
	public void spendPoints(Context context,float point) {
		getAdInstance(context).SpendAmount(point, null) ;
	}

	@Override
	public void free(Context context) {
		getAdInstance(context).finalize() ;
	}

	@Override
	public void getPoints(Context context) {
		Log.d("DatouniaoAd", "----getPoints ") ;
		getAdInstance(context).GetAmount(this) ;		
	}


}
